<?php
if(!defined('IN_MYMPS')) exit('Forbidden');
if(submit_check('password_submit')){
	
	if(empty($userpwd) && empty($safeanswer)) write_msg('','?m=password&error=19');
	if(!empty($userpwd) && ($userpwd != $reuserpwd)) write_msg('','?m=password&error=20');
	
	if (empty($safeanswer) && !empty($userpwd)) {
	
		if(defined('UC_CONNECT') && @include MYMPS_ROOT.'/uc_client/client.php'){
			$result =  uc_user_edit($s_uid, $userpwd, $userpwd, $email, 1);
			if($result == 1) {
				$result = 1;
			} elseif ($result == -4) {
				write_msg('','?m=password&error=21');
			} elseif ($result == -5) {
				write_msg('','?m=password&error=22');
			} elseif ($result == -6) {
				write_msg('','?m=password&error=23');
			} elseif ($result == -8) {
				write_msg('','?m=password&error=24');
			} elseif ($result == -1) {
				write_msg('','?m=password&error=25');
			} else {
				write_msg('','?m=password&error=26');
			}
		}
		
		$sql = "UPDATE `{$db_mymps}member` SET userpwd='".md5($userpwd)."' WHERE userid = '$s_uid'";		
	} elseif (!empty($safeanswer) && empty($userpwd)){
		$sql = "UPDATE `{$db_mymps}member` SET safequestion='$safequestion',safeanswer='$safeanswer' WHERE userid = '$s_uid'";
	} elseif (!empty($safeanswer) && !empty($userpwd)){
		$sql = "UPDATE `{$db_mymps}member` SET userpwd='".md5($userpwd)."',safequestion='$safequestion',safeanswer='$safeanswer' WHERE userid = '$s_uid'";
	} else {
		write_msg('','?m=password&error=13');
	}
	
	$db->query($sql);
	write_msg('','?m=password&success=8');

}else{
	require MYMPS_DATA.'/safequestions.php';
	$location = location();
	include mymps_tpl('password');
}
?>